package com.example.module_filemanage.Utils;

import android.util.Log;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

import static android.content.ContentValues.TAG;

/**
 * Created by SJ on 2018/4/19.
 */

public class TimeTool {

    public static String  Unixtotime(long timestamp){
        Date date=new Date();
        date.setTime(Long.valueOf(String.valueOf(timestamp).substring(0,10))*1000);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String riqi=sdf.format(date);
        return riqi;
    }
    public static String getcurrentTime(){
        Calendar date = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
        int dat = date.get(Calendar.HOUR) -24;
        date.set(Calendar.HOUR, dat);
        String year = String.valueOf(date.get(Calendar.YEAR));//年份
        int month = date.get(Calendar.MONTH) + 1; //月份
        int sdate = date.get(Calendar.DATE);//日期
        int hour =date.get(Calendar.HOUR);//日期
        String dd=year+format(month)+format(sdate)+format(hour)+"0000";
        Log.e(TAG, "getcurrentTime: "+date );
        return dd;
    }
    public static String getcurrentodTime(){
        Calendar date = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
        int dat = date.get(Calendar.HOUR) -1;
        date.set(Calendar.HOUR, dat);
        String year = String.valueOf(date.get(Calendar.YEAR));//年份
        int month = date.get(Calendar.MONTH) + 1; //月份
        int sdate = date.get(Calendar.DATE);//日期
        int hour =date.get(Calendar.HOUR);//日期
        String dd=year+format(month)+format(sdate)+format(hour)+"0000";
        Log.e(TAG, "getcurrentTime: "+date );
        return dd;
    }
    /**====================================================================*/
    public static String format(int time)
    {
        if (time<10){
            return "0"+String.valueOf(time);
        }
        return String.valueOf(time);
    }
}
